<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * User Application Controller: Groups
 * Started: September 19, 2009 11:09 AM
 * Script version: 1.0
 */
class group{
	public function __construct($identifier, $loadPerm = true){
		global $db;
		$this->gid = intval($identifier);
		$query = $db->select("groups", "*", "1", " WHERE `id` = {$this->gid}");
		if($query){
			if($db->num_rows($query) == 0){
				$this->status = false;
			}
			else{
				$this->group = $db->fetch_array($query);
				$this->status = true;
			}
		}
		else{
			$this->status = false;
		}
		//---------------------------------------
		// Permissy?
		//---------------------------------------
		if($this->status !== false and $loadPerm == true){
			$this->permission = new permissionmask($this->group['permissionmask']);
		}
	}
	
	public function getStatus(){
		return $this->status;
	}
	
	public function getName(){
		return $this->group['groupname'];
	}
	
	public function getID(){
		return $this->group['id'];
	}
	
	public function getDesc(){
		return $this->group['groupdesc'];
	}
	
	public function getPermMaskID(){
		return $this->group['permissionmask'];
	}
	
	public function getPrefix(){
		return $this->group['group_display_prefix'];
	}
	
	public function getSuffix(){
		return $this->group['group_display_suffix'];
	}
	
	public function is_native(){
		return $this->group['is_native'];
	}
	
	public function is_admin(){
		return $this->group['is_admin'];
	}
	
	public function is_smod(){
		return $this->group['is_smod'];
	}
	
	public function is_banned(){
		return $this->group['is_banned'];
	}
	
	public function delete(){
		global $db;
		if($this->is_native !== 1){
			$query = $db->query("DELETE FROM `".DB_PREFIX."groups` WHERE `id` = {$this->gid} LIMIT 1");
			return $query;
		}
		else{
			return false; # Cannot delete native group?
		}
	}
}
